/*
 * Copyright (C) 2014 Will Dignazio
 * coalesced.c
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <coalesce.h>

int
main(int argc, char *argv[])
{
	Error err;
	pid_t pid;
	pid_t sid;
	int ret;

	pid = fork();
	if(pid < 0)
		exit(EXIT_FAILURE);

	if(pid > 0)
		exit(EXIT_SUCCESS);

	umask(0);

	sid = setsid();
	if(sid < 0)
		exit(EXIT_FAILURE);

	ret = error_setfile("err.log");
	if(ret != 0)
		exit(EXIT_FAILURE);

	ret = conf_load("test.conf", &err);
	if(ret != 0)
		goto err;

	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);

err:
	return ret;
}
